﻿using System;

namespace ThresholdAssistant.Redis
{
    /// <summary>
    /// 
    /// </summary>
    public class RedisClientLockNx : IDisposable
    {
        /// <summary>
        /// 
        /// </summary>
        private readonly string _key;

        /// <summary>
        /// 客户端
        /// </summary>
        private readonly IRedisClient _client;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="client"></param>
        internal RedisClientLockNx(string key, IRedisClient client)
        {
            this._key = key;
            this._client = client;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Unlock()
        {
            //删除缓存
            return _client.DeleteKey(_key);
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            Unlock();
        }
    }
}
